﻿#include "tip.h"
#include "ui_tip.h"

Tip::Tip(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Tip_WT)
{
    ui->setupUi(this);
    drawArrow();
    QGraphicsDropShadowEffect *mainShadow = new QGraphicsDropShadowEffect(this);
    mainShadow->setOffset(0,0); // 设置阴影偏移量
    mainShadow->setBlurRadius(5); // 设置阴影模糊半径
    mainShadow->setColor(QColor(100, 100, 100)); // 设置阴影颜色（RGBA）
    ui->Tip_content_WT->setGraphicsEffect(mainShadow);
}

Tip::~Tip()
{
    delete ui;
}

void Tip::drawArrow(){
    int width=ui->arrow_LB->width();
    int height=ui->arrow_LB->height();
    QPixmap pixmap(ui->arrow_LB->size());
    QPixmap pixmap_white(ui->arrow_LB->size());
    pixmap.fill(Qt::transparent); // 使用透明背景填充新的QPixmap
    pixmap_white.fill(Qt::white);

    QPainter painter(&pixmap);
    painter.setRenderHint(QPainter::Antialiasing);//设置抗锯齿

    QPoint startPoint(0, height);
    QPoint centerPoint(width/2, 0.50*height);//顶点
    QPoint endPoint(width, height);

    QPainterPath path;

    QPolygon polygon;
    polygon << startPoint<< centerPoint<< endPoint<<startPoint;
    path.addPolygon(polygon);
    painter.setClipPath(path);
    painter.drawPixmap(0,0,pixmap_white);
    painter.drawLine(startPoint, centerPoint);
    painter.drawLine(centerPoint, endPoint);
    painter.end();
    ui->arrow_LB->setPixmap(pixmap);
}

void Tip::setText(const QString &text){
    ui->tipText_LB->setText(text);
}
